<template>
  <div class="id-card-uploader" style="text-align: center">
    <van-uploader max-count="1"
                  :upload-text="descriptionTxtA?descriptionTxtA:'文件上传1'"
                  :upload-icon="cardFrontBackground"
                  v-model="frontSelectList"
                  :after-read="uploadIDCardFrontCallBack"
    ></van-uploader>

    <van-uploader max-count="1"
                  :upload-text="descriptionTxtB?descriptionTxtB:'文件上传2'"
                  :upload-icon="cardBackBackground"
                  v-model="backSelectList"
                  :after-read="uploadIDCardBack"
    ></van-uploader>
  </div>
</template>


<script setup lang="ts">

/**
 * vant 自定义身份证上传组件
 */
import {ref} from 'vue';

const props: any = defineProps({
  // 定义上传图片的回调函数(传递给给父组件)
  frontCallBack: Function,
  backCallBack: Function,

  // 定义上传图片的数组
  frontFileList: Array,
  backFileList: Array,

  // 头像图片(父组件传进来)
  cardFrontBackground: String,
  cardBackBackground: String,

  // 控件描述信息
  descriptionTxtA: String,
  descriptionTxtB: String,
})

const frontSelectList = ref(props.frontFileList)
const backSelectList = ref(props.backFileList)


/**
 * 上传身份证正面
 * @param file 文件
 */
const uploadIDCardFrontCallBack = (file: any) => {
  props.frontCallBack(file);
}

/**
 * 身份证反面
 * @param file 文件
 */
const uploadIDCardBack = (file: any) => {
  props.backCallBack(file);
}

</script>

<style scoped>


:deep(.van-uploader__upload) {
  width: 44vw;
  height: 110px;

  /*
  需要用到 !important 才能生效
  width: 80vw !important;
  height: 150px !important;
  */
}

:deep(.van-image) {
  width: 44vw;
  height: 110px;

  /*
  需要用到 !important 才能生效
  width: 80vw !important;
  height: 150px !important;
  */
}

:deep(.van-uploader__preview-image) {
  width: 44vw;
  height: 110px;

  /*
  需要用到 !important 才能生效
  width: 80vw !important;
  height: 150px !important;
  */
}


:deep(.van-uploader__upload-text) {
  margin-top: 8px;
  color: #969799;
  font-size: 12px;
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 30px;
  line-height: 30px;
  background: #7eb3dc;
  color: #fff;
  text-align: center;
}

:deep(.van-uploader__upload,.van-image) {
  background: #E8F6FE;
  border-radius: 10px;
  overflow: hidden;
}

:deep(.van-icon__image) {
  width: 4em;
  height: 3em;
  -o-object-fit: contain;
  object-fit: contain;
  margin-bottom: 23px;
}

</style>

<!-- 使用方式 ：-->
<!--

  <template>
    <CustomIDCardUploader
          :front="front"
          :back="cardBack"
          :frontCallBack="uploadIDCardFront"
          :backCallBack="uploadIDCardBack">
      </CustomIDCardUploader>
  </template>


<script setup lang="ts">
import CustomIDCardUploader from "@/components/CustomIDCardSelect.vue";

/**
 * 上传身份证正面
 * @param file 文件
 */
const uploadIDCardFront = (file: any) => {
  console.log(file);
}

/**
 * 身份证反面
 * @param file 文件
 */
const uploadIDCardBack = (file: any) => {
  console.log(file);
}
</script>

-->
